import java.util.Scanner;
public class homework {
   /* public static void main(String[] args) {
        int count = 0;
        for (int  i = 0; i  < 100; i++) {
            if(i%10==9||i>=90)
            {
                count++;
            }
        }
        System.out.println(count);

    }*/
    /*public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int i=scanner.nextInt();
            for ( int j = 2; j < i; j++) {
                if(i%j==0){
                    System.out.print("该数不是素数");
                    break;
                }
                else {
                    System.out.println("该数是素数");
                    break;
                }
            }
        }*/

    /*public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int input=scanner.nextInt();
        for(int i=0;i<input;i++){
            for(int j=0;j<input;j++){
                if((i==j)||(i+j==input-1)){
                    System.out.print("*");
                }
                else{
                    System.out.print(" ");
                }
            }
            System.out.printf("\n");
        }
    }*/

    /*public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a=0;
        int c=0;
        int mart=0;
        for (int i = 1; i < n; i++) {
            mart=i;
            c=0;
            while (mart!=0) {
                a = mart % 10;
                mart = mart / 10;
                c = c + a * a * a;
            }
            if(c==i){
                System.out.println(i);
            }
        }
    }*/

    /*public static void main(String[] args) {
        double a=1;
        double b=0;
        for (double i = 1; i <=100; i++) {
            b=b+a/i;
            a=-a;
        }
        System.out.println(b);
    }*/

    //求最大公约数
    /*public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        if(n<m) {
            for (int i = n; i >=1 ; i--) {
                if(n%i==0&&m%i==0) {
                    System.out.println(i);
                    break;
                }
            }
        }
        else{
            for (int i = m; i >=1 ; i--) {
                if(n%i==0&&m%i==0) {
                    System.out.println(i);
                    break;
                }
            }
        }
    }*/

    //二进制中1的个数
   /* public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;

        while (n > 0) {
            if((n&1)==1){
                count++;
            }
            n=n>>1;
        }
        System.out.println(count);
    }*/

    //辗转相除法求公约数
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int a=n%m;

            while (a != 0) {
                n = m;
                m = a;
                a = n % m;
            }
            System.out.println(m);
        
    }
}





















